﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;

namespace Jackie.Silverliight.SetpBySetp.Html
{
    public partial class AddEventToElement : Page
    {
        public AddEventToElement()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            HtmlElement parent = HtmlPage.Document.GetElementById("parent");

            HtmlElement button = HtmlPage.Document.CreateElement("a");
            button.SetAttribute("innerText", "改变Silverlight中的颜色");
            button.SetAttribute("href", "#");
            button.CssClass = "newstyle";

            parent.AppendChild(button);

            button.AttachEvent("onclick", new EventHandler<HtmlEventArgs>(button_click));
        }

        private void button_click(object sender, HtmlEventArgs e)
        {
            result.Stroke = new SolidColorBrush(Colors.Black);
            result.Fill = new SolidColorBrush(Colors.Green);
            result.StrokeThickness = 2;
        }
    }
}
